<template>
  <div class="header">
    <div class="logo" @click="goToIndex()">
      <div class="logo-div">
        <img id="logo-img" :src="logo">
      </div>
      <div class="logo-title">笔迹分析系统</div>
    </div>
    <div class="header-right">
      <div class="header-user-con">
        <div class="user-avator">
          <img :src="user.portrait"/>
        </div>
        <div><i>&nbsp;</i></div>
        <!-- 用户名下拉菜单 -->
        <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                    <span class="el-dropdown-link">
                        {{username}}
                        <i class="el-icon-caret-bottom"></i>
                    </span>
          <template #dropdown>
            <el-dropdown-menu>
              <a href="/userIn/userInfo" target="_blank">
                <el-dropdown-item>个人中心</el-dropdown-item>
              </a>
              <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script>

import logo from "@/assets/img/logo.jpg"
export default {
  name: "CustomerHeader",
  data() {
    return {
      fullscreen: false,
      user: {
        portrait: ""
      },

      name: "account",
      message: 2,
      path: this.$route.path,
      analysis: "background-color: #546380;",
      history: "background-color: #546380;",
      logo: logo,
    };
  },
  computed: {
    username() {
      let user = {};
      if (localStorage.getItem("SESSION_KEY_USER") !== null) {
        user = JSON.parse(localStorage.getItem("SESSION_KEY_USER"));
      }
      this.user = user;
      return user.account ? user.account : this.name;
    },
    style1(){
      return "background-color: #546380;";
    },
    style2(){
      return "background-color: #01A7F0;";
    }
  },
  methods: {
    // 用户名下拉菜单选择事件
    handleCommand(command) {
      if (command == "loginout") {
        localStorage.removeItem("SESSION_KEY_USER");
        this.$router.push("/login");
      }
    },
    pushIndex(item) {
      this.$router.push(item);
      this.path = "/home/" + item;
      this.checkIndex()
    },
    selectStyle(itemStyle) {
      if (itemStyle === 'analysis'){
        this.analysis = this.style2;
      }else {
        this.history = this.style2;
      }
    },
    outStyle(index) {
      if (this.path!=="/home/"+index){
        if (index === 'analysis'){
          this.analysis = this.style1;
        }else {
          this.history = this.style1;
        }
      }
    },
    checkIndex(){
      if (this.path === "/home/analysis"){
        this.analysis = this.style2;
      }else if (this.path === "/home/history"){
        this.history = this.style2;
      }
    },
    goToIndex() {
      if (localStorage.getItem("SESSION_KEY_USER")) {
        this.$router.push({name:"UserIndex"})
      } else {
        this.$router.push({name:"Index"})
      }
    }
  },
  mounted() {
    this.checkIndex()
  },
};
</script>

<style scoped>
.my-menu {
  margin-right: 100px;
}

.my-button {
  display: inline-block;
  /*background-color: #546380;*/
  height: 25px;
  width: 70px;
  margin-right: 1px;
  border-radius: 5%;
  font-size: 10px;
  color: #fff;
  text-align: center;
  line-height: 25px;
}

.header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  font-size: 22px;
  /*background-color: #3B9AF5;*/
  color: #ffffff;
}

.header .logo {
  display: flex;
  margin-left: 30px;
  margin-top: 12px;
  float: left;
  width: 250px;
  line-height: 40px;
}

.header-right {
  float: right;
  padding-right: 50px;
}
.logo-title {
  margin-left: 17px;
  line-height: 50px;
}

.header-user-con {
  display: flex;
  height: 70px;
  align-items: center;
}

.user-name {
  margin-left: 10px;
}

.user-avator {
  margin-left: 20px;
}

.user-avator img {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.el-dropdown-link {
  color: #fff;
  cursor: pointer;
}
/*.logo {*/
/*  display: flex;*/
/*  align-items: center;*/
/*  top: 50%;*/
/*}*/
#logo-img {
  width: 46px;
  height: 46px;
  border-radius: 30%;
}
</style>